package test;
//给定一个数组，将数组中的元素拼接成一个字符串，例如数组{1,2,3}拼接成的字符串为"[1, 2, 3]"。
//另外一种方法看 StringBUilderTest12
public class Splicing {
    public static void main(String[] args) {
        int[] arr = {1,2,3};
        String a =speak(arr);
        System.out.println(a);
    }
    public static String speak( int[] arr ){
        if(arr == null  ){
           return null;
        }
        if(arr.length ==0 ){
         return "[]";
        }
     String result = "[";
        for(int i =0 ; i<arr.length ; i++){
            if(i == arr.length-1){
                result = result +arr[i];
            }else{
                result = result +arr[i]+", ";
            }
        }
        String result1 = "]";
        String resulta = result + result1;
        return resulta ;
    }
}

